package com.zh.config;

/**
 * @Description:
 * @ClassName RedisExpireListener
 * @date: 2021.04.21 10:36
 * @Author: zhanghang
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

/**
 * Redis缓存key过期监听
 *
 * @author single-聪
 * @date 2019年11月22日
 * @version 0.0.1
 */
@Slf4j
@Configuration
public class RedisExpireListener extends KeyExpirationEventMessageListener {


    public RedisExpireListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    /**
     * 针对 redis 数据失效事件，进行数据处理
     *
     * @param message
     * @param pattern
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.out.println("过期"+message.toString());
        System.out.println("123456");
        System.out.println(new String(pattern));
    }



}
